package com.rpp.controller;

import com.rpp.entity.Article;
import com.rpp.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @Description
 * @Author rpp
 * @Date 2020/7/14 10:31 下午
 */
@Controller
public class ArticleController {

    @Autowired
    ArticleService articleService;

    /**
     * @param pageNum
     * @param pageSize
     * @return
     */
    @RequestMapping("index")
    public String test(@RequestParam(name = "pageNum", required = false, defaultValue = "0") Integer pageNum,
                       @RequestParam(name = "pageSize", required = false, defaultValue = "3") Integer pageSize,
                       Model model) {

        Page<Article> page = articleService.findArticleByPage(pageNum, pageSize);

        model.addAttribute("articles", page);

        return "client/index";
    }
}
